<%@page import="com.nebula.common.Const"%>
<%@page import="com.nebula.pojo.User"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%
	User user = (User) session.getAttribute(Const.USERINFO);
 %>

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="static/html5shiv.js"></script>
<script type="text/javascript" src="static/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/h-ui.admin/css/style.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/layer/2.4/skin/layer.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/magic-input.min.css" />
<!--[if IE 6]>
<script type="text/javascript" src="static/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>视频</title>
</head>
  
<body>
<input type="hidden" value="<%=user.getUsername()%>" id="user">
<input type="hidden" value="<%=request.getAttribute("parentId")%>" id="pid">
<div class="page-container">
	<div class="cl pd-5 bg-1 bk-gray"> 
		<span class="l">
			<a class="btn btn-primary radius" data-title="文件上传" data-href="#" onclick="upload_files('文件上传')" href="javascript:;">
				<i class="Hui-iconfont">&#xe642;</i> 上传
			</a>
			&nbsp;
			<span id="group-span" class="btn-group r" style="display: none;">
				<a class="btn btn-secondary-outline radius" id="share" data-title="分享" data-href="#" onclick="share()" href="javascript:;">
					<i class="Hui-iconfont">&#xe6aa;</i> 分享
				</a>
				<a class="btn btn-secondary-outline radius" id="download" data-title="下载" data-href="#" onclick="plDownload()" href="javascript:;">
					<i class="Hui-iconfont">&#xe641;</i> 下载
				</a>
				<a class="btn btn-secondary-outline radius" id="delete" data-title="删除" data-href="#" onclick="del()" href="javascript:;">
					<i class="Hui-iconfont">&#xe6e2;</i> 删除
				</a>
				<a class="btn btn-secondary-outline radius" id="rename" data-title="重命名" data-href="#" onclick="rename()" href="javascript:;">
					<i class="Hui-iconfont"></i> 重命名
				</a>
				<a class="btn btn-secondary-outline radius" id="copyto" data-title="复制到" data-href="#" onclick="copyTo()" href="javascript:;">
					<i class="Hui-iconfont"></i> 复制到
				</a>
				<a class="btn btn-secondary-outline radius" id="moveto" data-title="移动到" data-href="#" onclick="moveTo()" href="javascript:;">
					<i class="Hui-iconfont"></i> 移动到
				</a>
			</span>
		</span>
		<span class="r">
			<input type="text" name="queries" id="queries" placeholder=" 搜索您的文件" style="width:250px" class="input-text">
			<button name="search" id="search" class="btn btn-success" type="submit" title="搜索"><i class="Hui-iconfont">&#xe665;</i></button>
			&nbsp;
			<a class="btn btn-success radius r" style="line-height:1.6em;" 
				href="javascript:location.replace(location.href);" title="刷新" >
				<i class="Hui-iconfont">&#xe68f;</i>
			</a>
		</span>
	</div>
	<div class="mt-10">
		<table class="table table-border table-bg table-hover table-sort table-responsive" >
			<thead id="t-head">
				<tr class="text-c">
					<th width="10"><input type="checkbox" class="mgc mgc-primary" name="checkAll" onclick="CheckAll(this)"></th>
					<th class="text-l">文件名</th>
					<th width="120">大小</th>
					<th width="240">修改日期</th>
				</tr>
			</thead>
			<tbody id="fileList">
				<c:if test="${empty list}">
					<table>
      					<tr><td><span style="font-size: 16px">暂无数据......</span></td></tr>
					</table>
				</c:if>
				<c:if test="${!empty list}">
					<c:forEach items="${list}" var="val">
					<tr class="text-c">
						<td width="10"><input type="checkbox" class="mgc mgc-primary" name="fileOrFolder" value="${val.fileid}" onclick="showSpan(this)"></td>
						<td class="text-l">
							<a style="cursor:pointer;font-size: 16px;" 
							href="javascript:;"
							target="_blank"
							class="text-primary"
							onClick="documentRead('${val.fileExtension}','${val.fileRealName}','${val.fileShortUrl}')">
							<img alt="" src="${pageContext.request.contextPath}/${val.icon}">
							&nbsp;&nbsp;<span>${val.fileRealName}</span></a>
						</td>
						<td>${val.fileSize}</td>
						<td width="200">${val.updatedtime}</td>
					</tr>
				</c:forEach>
				</c:if>
			</tbody>
		</table>
	</div>
	<div class="dataTables_wrapper">
		<div class="dataTables_info">显示 ${pageInfo['start']} 到 ${pageInfo['end']} ，共 ${pageInfo['total']} 条</div>
		<div class="dataTables_paginate">
			<c:choose>
				<c:when test="${pageInfo['pageNum'] != 1}">
					<a href="/nebula/file/other.action?pageNum=${pageInfo['pageNum'] - 1}"
					class="paginate_button">上一页</a>
				</c:when>
			</c:choose>
			<span>
				<c:forEach items="${pageInfo['pageArr']}" var="val">
					<c:choose>
						<c:when test="${val == pageInfo['pageNum']}">
								<a href="/nebula/file/other.action?pageNum=${val}" 
									class="paginate_button current">${val}</a>
						</c:when>
						<c:otherwise>
							<a href="/nebula/file/other.action?pageNum=${val}" 
							class="paginate_button">${val}</a>
						</c:otherwise>
					</c:choose>
				</c:forEach>
			</span>
			<c:choose>
				<c:when test="${pageInfo['pageNum'] != pageInfo['totalPages']}">
					<a href="/nebula/file/other.action?pageNum=${pageInfo['pageNum'] + 1}"
					 class="paginate_button next">下一页</a>
				</c:when>
			</c:choose>
		</div>
	</div>
</div>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath}/static/layer/2.4/layer.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/h-ui.admin/js/H-ui.admin.js"></script>

<script type="text/javascript" src="${pageContext.request.contextPath}/static/laypage/1.2/laypage.js"></script>
<script type="text/javascript">
$("#search").click(function(){
	if($("#queries").val() == ""){
		layer.msg("请输入你搜索的内容",{time:1500,offset:"t"});
	}else{
		window.location = "/nebula/fileAndFolder/search_list.action?queries="+$("#queries").val();
	}
})

$("#queries").bind("keypress",function(event){
	if(event.keyCode == "13"){
		$("#search").click();
	}
})

function upload_files(title){
	var index = layer.open({
		type: 2,
		area: ['1050px','600px'],
		fix: false, //不固定
		title: title,
		maxmin: true,
		closeBtn:0,
		shade:false,
		content:"/nebula/folder/upload.action?folderId="+$("#pid").val()+""
	});
}

function CheckAll(obj){
	var allSel = document.getElementsByName("fileOrFolder");
	if(obj.checked){
		for(i = 0;i < allSel.length;i++){
			allSel[i].checked = true;
		}
		$("#group-span").show();
		$("#rename").addClass('disabled');
		$("#t-head").html("<tr><td><input class='mgc mgc-primary' type='checkbox' checked=true name='checkAll' onclick='CheckAll(this)'></td>"+
		"<td>已选中"+$("input[name=fileOrFolder]:checked").size()+"个文件/文件夹</td><td width='120'></td><td width='240'></td></tr>")
		$("#fileList").find('tr').attr("style","background-color: #f5f5f5");
	}else{
		for(i = 0;i < allSel.length;i++){
			allSel[i].checked = !allSel[i].checked;
		}
		$("#group-span").hide();
		$("#t-head").html("<tr class='text-c'>"+
					"<th width='10'><input class='mgc mgc-primary' type='checkbox' name='checkAll' onclick='CheckAll(this)'></th>"
					+"<th class='text-l'>文件名</th>"
					+"<th width='120'>大小</th>"
					+"<th width='240'>修改日期</th>"
				+"</tr>")
		$("#rename").removeClass('disabled');
		$("#fileList").find('tr').removeAttr("style","background-color: #f5f5f5");
	}
}

function showSpan(obj){
	if(obj.checked){
		$("#group-span").show();
		$("#t-head").html("<tr><td><input class='mgc mgc-primary' type='checkbox' name='checkAll' onclick='CheckAll(this)'></td>"+
		"<td>已选中"+$("input[name=fileOrFolder]:checked").size()+"个文件/文件夹</td><td width='120'></td><td width='240'></td></tr>")
		$(obj).parent().parent().attr("style","background-color: #f5f5f5");
	}else if($("input[name=fileOrFolder]:checked").size() == 0){
		$("#group-span").hide();
		$("#t-head").html("<tr class='text-c'>"+
					"<th width='10'><input class='mgc mgc-primary' type='checkbox' name='checkAll' onclick='CheckAll(this)'></th>"
					+"<th class='text-l'>文件名</th>"
					+"<th width='120'>大小</th>"
					+"<th width='240'>修改日期</th>"
				+"</tr>")
		$(obj).parent().parent().removeAttr("style");
	}else{
		$("#t-head").html("<tr><td><input class='mgc mgc-primary' type='checkbox' name='checkAll' onclick='CheckAll(this)'></td>"+
		"<td>已选中"+$("input[name=fileOrFolder]:checked").size()+"个文件/文件夹</td><td width='120'></td><td width='240'></td></tr>")
		$(obj).parent().parent().removeAttr("style");
	}
	if($("input[name=fileOrFolder]:checked").size() > 1){
		$("#rename").addClass('disabled');
	}else{
		$("#rename").removeClass('disabled');
	}
}

function share(){
	var valArr = [];
	var title = "分享文件(夹):";
	var s = "";
	var value = $("input[name=fileOrFolder]:checked").parent().next().eq(0).find('a span').text();
	var length = $("input[name=fileOrFolder]:checked").size();
	if(length > 1){
		title += value + "等";
		s += value + "等";
	}else{
		title += value;
		s += value;
	}
	$("input[name=fileOrFolder]:checked").each(function(i){
		valArr[i] = $(this).val();
	})
	var index = layer.open({
		type: 2,
		title: title,
		area :['550px','400px'],
		content: "/nebula/choose-share.action?valArr="+valArr+"&title="+encodeURIComponent(encodeURIComponent(s))
	});
}

function plDownload(){
	var valArr = [];
	$("input[name=fileOrFolder]:checked").each(function(i){
		if($(this).val().length <= 11){
			alert("文件夹下载功能暂未开发");
			return false;
		}else{
			valArr[i] = $(this).val();
		}
	})
	var url;
	if(valArr == ""){
		return false;
	}else if(valArr.length == 1){
		url = "/nebula/file/download.action;jsessionid=<%=session.getId()%>;code="+randomString(4)
		+"?fileId="+valArr[0];
		layer.msg('正在准备下载，请稍后...',{offset:"t"});
		window.location = url;
	}else{
		layer.confirm("文件打包过程可能需要很长一段时间，确定使用打包下载吗？（大文件不建议使用）",{title:"确定使用打包下载"},function(index){
			var i;
			$.ajax({
				type: "post",
				url: "/nebula/file/compress.action",
				data : {
					fileIdGroup : function(){
						return valArr;
					}
				},
				dataType : "json",
				beforeSend: function(){
					i = layer.msg('文件正在打包，打包过程时间较长，请耐心等待...', {icon: 16,shade: [0.5, '#f5f5f5'],scrollbar: false,offset: '0px', time:-1}) ;  
				},
				success : function(data){
					layer.close(i);
					if(data.status == 0){
						url = "/nebula/file/plDownload.action;jsessionid=<%=session.getId()%>;code="+randomString(4)
						+"?zipname="+data.data.zipname+"&ctm="+data.data.ctm;
						console.log(url);
						window.location = url;
					}else{
						layer.msg(data.msg);
					}
				}
			});
			layer.close(index);
		});
	}
}

function del(){
	layer.confirm("确认把所选文件删除吗？",{icon: 3,title:"确认删除"},function(index) {
		var valArr = [];
		$("input[name=fileOrFolder]:checked").each(function(i){
			valArr[i] = $(this).val();
		})
		$.ajax({
			type : "post",
			url : "/nebula/folder/plDel.action",
			data : {
				groupId : function(){
					return valArr;
				}
			},
			dataType : "json",
			success : function(data){
				if(data.status == 0){
					layer.msg(data.msg, {icon:1,time:1000,offset:['0','']}, function(){
						location.reload();
					});
				}else if(data.status == 1){
					layer.msg(data.msg,{icon:2,offset:['0','']});
				}
			}
		})
		layer.close(index);
	})
}

function rename(){
	var value = $("input[name=fileOrFolder]:checked").parent().next().find('a span').text();
	value = value.substr(0,value.lastIndexOf("."));
	var length = $("input[name=fileOrFolder]:checked").val().length;
	var id = $("input[name=fileOrFolder]:checked").val();
	var prompt = layer.prompt({title:'重命名文件/文件夹',value:value},function(newName,index){
		var i;
		layer.close(index);
		var url;
		var data;
		if(length <= 11){
			url = "/nebula/folder/save.action";
			data = {folderid:id,folderName:newName,parentid:$("#pid").val(),username:$("#user").val()};
		}else{
			url = "/nebula/file/rename.action";
			data = {fileid:id,fileRealName:newName,folderId:$("#pid").val(),username:$("#user").val()};
		}
		$.ajax({
			type: "POST",
			url: url,
			data:JSON.stringify(data),
			dataType: "JSON",
			contentType:'application/json;charset=utf-8',
			beforeSend: function () {  
                i = layer.msg('正在重命名文件，请稍后...', {icon: 16,shade: [0.5, '#f5f5f5'],scrollbar: false,offset: '0px', time:100000}) ;  
            },
			success : function(data){
				if(data.status == 0){
					layer.close(i);
					layer.msg(data.msg,{offset:['0',''],icon: 1,time:1000},function(){
						location.reload();
					});
				}
			}
		});
	});
}

function copyTo(){
	var valArr = [];
	$("input[name=fileOrFolder]:checked").each(function(i){
		valArr[i] = $(this).val();
	})
	var index = layer.open({
		type: 2,
		area: ['520px','300px'],
		fix: false, //不固定
		title: "复制到",
		content:"/nebula/directory.action?valArr="+valArr+"&type=copy",
	});
}

function moveTo(){
	var valArr = [];
	$("input[name=fileOrFolder]:checked").each(function(i){
		valArr[i] = $(this).val();
	})
	var index = layer.open({
		type: 2,
		area: ['520px','300px'],
		fix: false, //不固定
		title: "移动到",
		content:"/nebula/directory.action?valArr="+valArr+"&type=move"
	});
}

function documentRead(ext,title,shortURL){
	if(ext.toLocaleLowerCase() == "txt"){
		var url = "/rs/" + shortURL;
		var index = layer.open({
			type: 2,
			title: title + " - 文本阅读",
			area :['800px','900px'],
			content: url
		});
	}
	if(ext.toLocaleLowerCase() == "pdf"){
		var url = "/rs/" + shortURL;
		var index = layer.open({
			type: 2,
			title: title + " - PDF阅读",
			content: url
		});
		layer.full(index);
	}
}

function randomString(len){
	len = len || 32;
	var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
	var maxPos = $chars.length;
	var pwd = '';
	for (i = 0; i < len; i++) {
　　　　	pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
　　	}
　　	return pwd;
}
</script>
</body>
</html>
